<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="../assets/css/bootstrap.min.css" />
<script src="../assets/js/jquery.min.js"></script>
<script src="../assets/js/bootstrap.min.js"></script>
<title>商品类型</title>
</head>
<body>
<div class="row" style="width:98%;margin-left: 1%;">
	<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
		<div class="panel panel-default">
			<div class="panel-heading">
				商品类型
			</div>
			<div class="panel-body">
				<div class="row">
					<div class="col-xs-5 col-sm-5 col-md-5 col-lg-5">
						<div class="form-group form-inline">
							<span>商品类型等级</span>
							<input type="text" name="flag" class="form-control">
						</div>
					</div>
					<div class="col-xs-5 col-sm-5 col-md-5 col-lg-5">
						<div class="form-group form-inline">
							<span>商品类型名称</span>
							<input type="text" name="name" class="form-control">
						</div>
					</div>
					<div class="col-xs-2 col-sm-2 col-md-2 col-lg-2">
						<button type="button" class="btn btn-primary" id="search"><span class="glyphicon glyphicon-search">搜索</span></button>
					</div>
				</div>
				<div style="height: 400px;overflow: scroll;">
				<table id="tb_list" class="table table-striped table-hover table-bordered">

				</table>
				</div>
			</div>
		</div>
	</div>
</div>
<script type="text/javascript">
    function ondelete(id){
        console.log(id)
        $.ajax({
            async: false,
            url:"http://localhost:80/phalapi/public/index.php?s=App.GoodsType.deleteGoodsTypeInfo",
            type: "POST",
            data : {
                goodType_id:id
            },
            dataType: "JSON",
            success: function (result) {

            },
            error: function (msg) {
                alert("错误信息：" + msg);
            }
        })
        window.location.replace("showGoodsType.php")
    }
    function onupdate(id,name,level){
        console.log(name)
        window.location.replace("updateGoodsType.php?id="+id+"&name="+name+"&level="+level);
    }
    //查询全部商品类别
    $(function () {
        $.ajax({
            url: "http://localhost:80/phalapi/public/index.php?s=App.GoodsType.getGoodsTypes",
            type: "GET",
            dataType: "JSON",
            success: function (result) {
                var user_data = result.data.info;
                var z = 1;
                console.log("data:" + user_data[0]['id'])
                // <li><a href='goods/goodsList.php'></a></li>
                var s = "<tr class='tr_head'><td>序号</td><td>类型</td><td>等级</td><td>操作</td></tr>";
                for (var i = 0; i < user_data.length; i++) {
                    var id = user_data[i]['id'];
                    var a = user_data[i]['name'];
                    var b = user_data[i]['level'];
                    // console.log('price_url=' + price_url)
                    s += "<tr><td>"+(z++)+"</td><td>"+a+"</td><td>"+b+"</td><td><button class='btn btn-primary' onclick='ondelete("+id+")' style='margin-right: 10px'>删除</button><button class='btn btn-primary' onclick='onupdate("+id+",this.name,"+b+")' name='"+a+"'>修改</button></td></tr>";
                }
                $("#tb_list").html(s);
            },
            error: function (msg) {
                alert("错误信息：" + msg);
            }
        })
    })

</script>
</body>
</html>